home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Programming / Python-1.4 / Source / Amiga / testset / test_links.py < prev   
Text File  |  1996-11-16  |  2KB  |  97 lines

  1.  
  2. import os
  3.  
  4. TestError = 'FAILED --- link test'
  5.  
  6. def test(a,b):
  7.     if a!=b: raise TestError
  8.  
  9. def test_fail(e):
  10.     global fail
  11.     if fail!=e:
  12.         raise TestError,'found err: '+`fail`+' wanted: '+`e`
  13.  
  14.  
  15. def remove_files():
  16.  try:
  17.     os.system("delete >NIL: t:#? all quiet force")
  18.     os.unlink("ram:t_hard")
  19.     os.unlink("ram:t_soft")
  20.     os.unlink("ram:dir_soft")
  21.     os.unlink("ram:dir_hard")
  22.  except os.error: pass
  23.  
  24. if os.getuid()!=0:
  25.     print "Sorry you are not root, cannot perform all link tests."
  26.     print "Log in as root and try again."
  27.     raise SystemExit,10
  28.  
  29. remove_files()
  30.  
  31. print 'TESTING ISXXX & LINK FUNCTIONS...'
  32. os.link("ram:t","ram:t_hard")
  33. os.symlink("ram:t","ram:t_soft")
  34. os.symlink("c:dir","ram:dir_soft")
  35. fail=0
  36. try: os.link("c:dir","ram:dir_hard")
  37. except os.error,e: fail=e[0]
  38. test_fail(22)    # invalid argument
  39. test(os.path.isdir("ram:t"), 1)
  40. test(os.path.isdir("ram:t_hard"),1)
  41. test(os.path.isdir("ram:t_soft"),1)
  42. test(os.path.isdir("ram:dir_soft"),0)
  43. test(os.path.isfile("ram:dir_soft"),1)
  44. test(os.path.isfile("ram:t_hard"),0)
  45. test(os.path.islink("ram:t_hard"),0)
  46. test(os.path.islink("ram:t_soft"),1)
  47. test(os.path.islink("ram:dir_soft"),1)
  48. test(os.path.islink("ram:dir_sof"),0)
  49.  
  50. print 'TESTING MKDIR & CIRCULAR LINKS...'
  51. fail=0
  52. try: os.mkdir("ram:dir_soft/foo",0644)
  53. except os.error,e: fail=e[0]
  54. test_fail(22)    # invalid argument
  55. os.mkdir("ram:t_soft/foo",0644)
  56. os.mkdir("ram:t_soft/bar",0000)
  57. os.mkdir("ram:t_soft/foo2",0700)
  58. os.mkdir("ram:t_soft/foo/bar",0070)
  59. os.mkdir("ram:t_soft/foo/bar2",0007)
  60. os.mkdir("ram:t_soft/foo/bar3",0777)
  61. os.symlink("c:dir","ram:t_soft/foo/bar2/dir_soft")
  62. os.symlink("c:dir","ram:t_soft/foo/bar2/dir_soft2")
  63. fail=0
  64. try: os.link("ram:t","ram:t_soft/foo/bar2/t_hard")
  65. except os.error,e: fail=e[0]
  66. test_fail(62)    # ELOOP
  67.  
  68. fail=0
  69. try: os.symlink("ram:t","ram:t_soft/foo/bar2/t_soft")
  70. except os.error,e: fail=e[0]
  71. test_fail(62)    # ELOOP
  72.  
  73. print 'TESTING READLINK...'
  74. fail=0
  75. try: os.readlink("ram:dir_sof")
  76. except os.error,e: fail=e[0]
  77. test_fail(2)    # no such file or dir
  78. test(os.readlink("ram:dir_soft"),"c:dir")
  79. test(os.readlink("ram:t_soft"),"ram:t")
  80. fail=0
  81. try: os.readlink("ram:t")
  82. except os.error,e: fail=e[0]
  83. test_fail(22)    # invalid argument
  84. fail=0
  85. try: os.readlink("ram:t_hard"),"error!!"
  86. except os.error,e: fail=e[0]
  87. test_fail(22)    # invalid argument
  88. test(os.readlink("ram:t_soft"),"ram:t")
  89. fail=0
  90. try: os.readlink("c:dir")
  91. except os.error,e: fail=e[0]
  92. test_fail(22)    # invalid argument
  93.  
  94. remove_files()
  95.  
  96. print 'LINK TEST OK'
  97.